/////////////////////////////////////////////////////////////////////////////////////////////
// Filename: ApplicationLayer.h
// (c) Dave Ottley, 2012. All rights reserved.
/////////////////////////////////////////////////////////////////////////////////////////////
#ifndef APPLICATIONLAYER_H
#define APPLICATIONLAYER_H

///////////////////////////
//		INCLUDES
///////////////////////////
#include <list>
#include <Windows.h>

///////////////////////////
//		MY INCLUDES
///////////////////////////
#include "StateMachine.h"
#include "Constants.h"

class D3DClass;
class InputClass;
class WindowsClass;
class GameTimer;
class Bitmap;
class GameTimer;


///////////////////////////
//		APPLICATIONLAYER
///////////////////////////
class ApplicationLayer
{
	bool mAppPaused;
	PlayerCount mPlayers;
	StateMachine<ApplicationLayer> * mStateMachine;
	D3DClass * mGraphics;
	InputClass * mInput;
	WindowsClass * mOS;
	GameTimer * mTimer;
	uint32_t mID;

	//SINGLETON
	ApplicationLayer();
	~ApplicationLayer(); //Force compiler error if not released
	ApplicationLayer(const ApplicationLayer&);
	ApplicationLayer& operator=(const ApplicationLayer& rhs);

public:
	static ApplicationLayer* GetInstance();
	bool Initialize(HINSTANCE hInstance, int nCmdShow);
	int Run();
	void Shutdown() { }
	void InitScene() { mGraphics->ClearScreen(); }
	void UpdateScene() { mStateMachine->Update(); }
	void PresentScene() { mGraphics->Present(); }
	void Pause() { if(mAppPaused) return; mAppPaused = true; mTimer->Stop(); Beep(500, 100); }
	void Unpause() { if(!mAppPaused) return; mAppPaused = false; mTimer->Start(); Beep(2000, 100); }
	const bool IsPaused() const { return mAppPaused; }
	const PlayerCount GetNumPlayers() const { return mPlayers; }
	void SetNumPlayers(PlayerCount players) { mPlayers = players; }
	StateMachine<ApplicationLayer> * GetFSM() const {return mStateMachine; }

	virtual bool HandleMessage(const Telegram& msg) { return mStateMachine->HandleMessage(msg); }
};



#ifndef ApplicationCls
#define ApplicationCls ApplicationLayer::GetInstance()
#endif

#endif // APPLICATIONLAYER_H